import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:xmshop/app/models/message.dart';
import 'package:xmshop/app/services/screebAdapter.dart';

import '../controllers/register_step_three_controller.dart';
import '../../../../widget/logo.dart';
import '../../../../widget/passButton.dart';
import '../../../../widget/passTextField.dart';

class RegisterStepThreeView extends GetView<RegisterStepThreeController> {
  const RegisterStepThreeView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        actions: [TextButton(onPressed: () {}, child: const Text("帮助"))],
      ),
      body: ListView(
        padding: EdgeInsets.all(ScreenAdapter.width(40)),
        children: [
          const Logo(),
          PassTextFiled(
            controller: controller.passController,
            hintText: "密码",
            keyboardType: TextInputType.text,
            isPassWord: true,
            onChanged: (value) {},
          ),
          PassTextFiled(
            controller: controller.confirmPassController,
            hintText: "确认密码",
            keyboardType: TextInputType.text,
            isPassWord: true,
            onChanged: (value) {},
          ),
          PassButton(
              text: "登录",
              onPressed: () async {
                // 判断密码是否合法并且相同
                if (controller.passController.text !=
                    controller.confirmPassController.text) {
                  Get.snackbar('提示', "密码不一致");
                } else if (controller.passController.text.length < 6) {
                  Get.snackbar('提示', "密码长度不能小于6位");
                } else {
                  MessageModel res = await controller.doRegister();
                  if (res.success) {
                    // 注册成功，执行跳转，回到根目录
                    Get.offAllNamed('/tabs', arguments: {"initialPage": 4});
                  } else {
                    Get.snackbar("提示", res.message);
                  }
                }
              })
        ],
      ),
    );
  }
}
